import matplotlib.pyplot as plt
import numpy as np

# 数据配置
labels = ['专业技能', '实践操作', '团队协作', '创新思维',
          '学习态度', '时间管理', '适应环境', '责任担当']
pre = [75, 70, 65, 60, 80, 65, 70, 70]
post = [85, 85, 80, 75, 85, 75, 85, 90]
x = np.arange(len(labels))  # 标签位置

# 绘图
fig, ax = plt.subplots(figsize=(12, 6))
bar_width = 0.35
rects1 = ax.bar(x - bar_width/2, pre, bar_width, label='前测', color='#1f77b4')
rects2 = ax.bar(x + bar_width/2, post, bar_width, label='后测', color='#ff7f0e')

# 添加标签与样式
ax.set_title('研学活动前后职业素养水平对比', fontsize=14, pad=20)
ax.set_xticks(x)
ax.set_xticklabels(labels, rotation=45, ha='right')
ax.set_ylim(0, 100)
ax.set_ylabel('平均分（0-100）')
ax.legend()

# 在柱子上标注数值
for rect in rects1 + rects2:
    height = rect.get_height()
    ax.annotate(f'{height}',
                xy=(rect.get_x() + rect.get_width()/2, height),
                xytext=(0, 3),  # 垂直偏移
                textcoords="offset points",
                ha='center', va='bottom')

plt.tight_layout()
plt.show()